﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework.Utils;
using CNVP.JShop.UI;
using CNVP.JShop.BLL;

namespace CNVP.JShop.Admin.Template.Operate
{
    public partial class Dynamic : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 102) || !BLL.BLLCheckAdmin.LoginOk(Page, 118) || !BLL.BLLCheckAdmin.LoginOk(Page, 119)) return;//判断页面权限
            if (!IsPostBack)
            {
                string _UnitID = Request.Params["UnitID"];
                string styleID = Request.Params["StyleID"];
                string templateID = Request.Params["TemplateID"];
                CNVP.JShop.BLL.CNVP_UnitsInfo bll = new CNVP.JShop.BLL.CNVP_UnitsInfo();
                DataTable Dt = bll.UnitStyleXmlList(Convert.ToInt16(templateID));
                DataTable Dt_Style = bll.GetUnitStyle(Convert.ToInt32(_UnitID), Convert.ToInt32(templateID));

                if (Dt_Style != null && Dt_Style.Rows.Count > 0)
                {
                    string Content = Dt_Style.Rows[0]["UnitHtml"].ToString();
                    if (!string.IsNullOrEmpty(Content))
                    {
                        CNVP.JShop.Publish.LabelMass labelmass = new CNVP.JShop.Publish.LabelMass(Content);
                        labelmass.ParseContent();
                        FCKeditor1.Value= labelmass.Parse();
                    }
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string _UnitID = Request.Params["UnitID"];
            string _StyleID = Request.Params["templateID"];
            string _Content = FCKeditor1.Value;
            if (!string.IsNullOrEmpty(_Content))
            {
                _Content = string.Format("[NT:UnLoop,NT:LabelType=Dynamic]{0}[/NT:UnLoop]", _Content);
            }
            CNVP.JShop.BLL.CNVP_UnitsInfo bll = new CNVP.JShop.BLL.CNVP_UnitsInfo();
            bll.UnitID = Convert.ToInt32(_UnitID);
            bll.StyleID = Convert.ToInt32(_StyleID);
            bll.UnitHtml = _Content;
            bll.EditUnitStyle();
            MessageUtils.Write("<script language=\"javascript\" type=\"text/javascript\">top.parent.location.reload();</script>");    
        }
    }
}
